﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="new_Default" enableEventValidation="false"  %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" defer="defer" src="../My97DatePicker/WdatePicker.js"></script>
    <script src="../js/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../js/jquery.autocomplete.js" type="text/javascript"  language="javascript"></script>
    <script src="../js/StockSearchData.js" language="javascript" type="text/javascript"></script>
    <script src="../js/jquery.query.url.js" type="text/javascript" language="javascript"></script>
    <script>
        $(document).ready(function () {
            var str = window.location.href;
            var pos = str.indexOf("?");
            var parastr = str.substring(pos + 1);
            $("#txtStock").autocomplete(EALists, {
                max: 10,
                minChars: 0,
                width: 160,
                matchContains: true,
                autoFill: false,
                formatItem: function (row, i, max) {
                    return row._C + " " + row._S + " " + row._N;
                },
                formatMatch: function (row, i, max) {
                    return row._C + " " + row._S + " " + row._N;
                },
                formatResult: function (row) {
                    return row._C;
                }
            });

            $("#cbkAll").click(function () {
                var chks = $("input[tt=aa]");
                for (var i = 0; i < chks.length; i++) {
                    chks[i].checked = this.checked;
                }
            })
            $("#btnPub").click(function () {
                var chks = $("input[tt=aa]");
                var ids = "";
                for (var i = 0; i < chks.length; i++) {
                    if (chks[i].checked) {
                        ids += chks[i].value + ",";
                    }
                }
                ids = ids.substring(0, ids.length - 1);
                document.getElementById("hidIds").value = ids;
            })
            $("#btnCancelPub").click(function () {
                var chks = $("input[tt=aa]");
                document.getElementById("hidIds").value = "";
                var ids = "";
                for (var i = 0; i < chks.length; i++) {
                    if (chks[i].checked) {
                        ids += chks[i].value + ",";
                    }
                }
                ids = ids.substring(0, ids.length - 1);
                document.getElementById("hidIds").value = ids;
            })
            $("#btnDelete").click(function () {
                var chks = $("input[tt=aa]");
                document.getElementById("hidIds").value = "";
                var ids = "";
                for (var i = 0; i < chks.length; i++) {
                    if (chks[i].checked) {
                        ids += chks[i].value + ",";
                    }
                }
                ids = ids.substring(0, ids.length - 1);
                document.getElementById("hidIds").value = ids;
            })
            $("#btnSelect").click(function () {
                var Title = $("#txtTitle").val()
                Title = encodeURI(Title);
                var date = $("#time").val();
                date = encodeURI(date);
                var edate = $("#etime").val();
                edate = encodeURI(edate);
                var Stock = $("#txtStock").val();
                Stock = encodeURI(Stock);
                var newsTypeId = $("#ddlNewType2").val();
                newsTypeId = encodeURI(newsTypeId);
                var id = $("#txtId").val();

                var url = "default.aspx?";

                var con = "";
                if (Title != "") {
                    if (con != "") {
                        con += "&title=" + Title;
                    }
                    else {
                        con = "title=" + Title;
                    }
                }
                if (edate != "") {
                    if (con != "") {
                        con += "&edate=" + edate;
                    } else {
                        con = "edate=" + edate;
                    }
                }
                if (date != "") {
                    if (con != "") {
                        con += "&date=" + date;
                    } else {
                        con = "date=" + date;
                    }
                }
                if (Stock != "") {
                    if (con != "") {
                        con += "&stock=" + Stock;
                    }
                    else {
                        con = "stock=" + Stock;
                    }
                }
                if (newsTypeId != "") {
                    if (con != "") {
                        con += "&newsTypeId=" + newsTypeId;
                    }
                    else {
                        con = "newsTypeId=" + newsTypeId;
                    }
                }
                if (id != "") {
                    if (id != "") {
                        con += "&id=" + id;
                    }
                    else {
                        con = "id=" + id;
                    }
                }
                document.location = url + con;
            })
            $("#ddlNewType1").change(function () {
                var pid = $(this).val();
                if (pid == "") {
                    $("#ddlNewType2").html("");
                }
                else {
                    $("#ddlNewType2").html("");
                    $.getJSON("NewsTypeHandler.ashx", { pid: pid }, function (data) {
                        var html = "";
                        $.each(data, function (i) {
                            html += " <option value='" + data[i].id + "'>" + data[i].name + "</option>";
                        })
                        $("#ddlNewType2").html(html);
                    })
                }
            })

            $("[IsStep=true]").change(function () {
                var step = $(this).val();
                var newsId = $(this).attr("NewsId");
                $.post("UpdateNewsStep.ashx", { newsId: newsId, step: step }, function (data) {
                    if (data == "0") {
                        alert("权重更新失败");
                    }
                })

            })

            var steps = $("[IsStep=true]");
            steps.each(function (i) {
                var value = $(steps[i]).attr("yy");
                $(steps[i]).val(value);
            })

            var newsTypeId = jQuery.query.GET("newsTypeId");

            if (newsTypeId != '' && newsTypeId != null && newsTypeId != 'null') {
                $.post("NewsTypeHandler.ashx", { flag: 'current', id: newsTypeId }, function (data) {
                    if (data == '') {
                        return;
                    }
                    data = eval('(' + data + ')');
                    $("#ddlNewType1").val(data.pid);
                    var html = "";
                    for (var i = 0; i < data.data.length; i++) {
                        html += " <option value='" + data.data[i].id + "'>" + data.data[i].name + "</option>";
                    }
                    $("#ddlNewType2").html(html);
                    $("#ddlNewType2").val(newsTypeId);
                })
            }
            var title = jQuery.query.GET("title");
            if (title != '' && title != null) {
                $("#txtTitle").val(title);
            }

            var date = jQuery.query.GET("date");
            if (date != '' && date != null) {
                $("#time").val(date);
            }

            var edate = jQuery.query.GET("edate");
            if (edate != '' && edate != null) {
                alert(edate)
                $("#edate").val(edate);
            }

            var stock = jQuery.query.GET("stock");
            if (stock != '' && stock != null) {
                $("#txtStock").val(stock);
            }
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="button_bar">
        <asp:Button ID="btnAdd" CssClass="common_button" runat="server" Text="添加" onclick="btnAdd_Click" 
           />
        <input type="button" id="btnSelect" value="查询" class="common_button" /><asp:Button
            ID="btnPub" runat="server" Text="发布" CssClass="common_button" OnClick="btnPub_Click"/>
        <asp:Button ID="btnCancelPub" runat="server" Text="取消发布" CssClass="common_button"
            OnClick="btnCancelPub_Click" Width="70px"/><asp:Button id="btnDelete" 
            value="批量删除" class="common_button"  runat="server"
                Text="批量删除" Width="70px" onclick="btnDelete_Click" OnClientClick="return confirm('确定删除？')"/>
    </div>
    <table class="query_form_table">
        <tr>
            <th>
                新闻标题
            </th>
            <td>
                <input type="text" id="txtTitle" />
            </td>
            <th>
                发布时间
            </th>
            <td>
                <input type="text" name="time" id="time" style="width:80px;" onfocus="WdatePicker()"/>
                至
                <input type="text" name="etime" id="etime" style="width:80px;" onfocus="WdatePicker()" />
</td>
            <th>
                股票
            </th>
            <td>
                <input type="text" id="txtStock"/>
            </td>
        </tr>
        <tr>
             <th>
                新闻类型
            </th>
            <td >
                <asp:DropDownList ID="ddlNewType1" runat="server">
                </asp:DropDownList>
                <asp:DropDownList ID="ddlNewType2" runat="server">
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <th>
                编号
            </th>
            <td colspan="4">
                <input type="text" id="txtId" />
            </td>
        </tr>
    </table>
    <div>
        <input id="hidIds" type="hidden" runat="server" />
        <table class="data_list_table">
            <tr>
                <th>
                    <input id="cbkAll" type="checkbox" />
                    全选
                </th>
                <th>
                    编号
                </th>
                <th>
                    标题
                </th>
                <th>权重</th>
                <th>
                    创建时间
                </th>
                <th>
                    发布时间
                </th>
                <th>
                    来源
                </th>
                <th>
                    是否已发布
                </th>
                <th>
                    操作
                </th>
            </tr>
            <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <tr>
                        <td class="list_data_number">
                            <input name="select" value='<%# Eval("id") %>' type="checkbox" tt="aa" id="select"
                                runat="server" />
                        </td>
                        <td class="list_data_number">
                            <%# Eval("id") %>
                        </td>
                        <td class="list_data_text">
                        
                            <a target="_blank" href='<%# GetNewsUrl(GetDataItem()) %>'>
                            <%# Eval("title") %></a>
                        </td>
                        <td>
                            <select IsStep="true" NewsId='<%# Eval("id") %>' yy='<%# Eval("step") %>' >
                                <option value="0">0</option>
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                            </select>
                        </td>
                        <td class="list_data_text">
                            <%# Eval("ctime", "{0:yyyy-MM-dd HH:mm:ss}")%>
                        </td>
                        <td class="list_data_text">
                            <%# Eval("ptime","{0:yyyy-MM-dd HH:mm:ss}")%>
                        </td>
                        <td>
                            <%# Eval("source") %>
                        </td>
                        <td class="list_data_text">
                            <%# Eval("IsEnable")%>
                        </td>
                        <td class="list_data_ltext">
                            <a href='edit.aspx?id=<%# Eval("id") %>&page=<%=GetPage() %>&newsTypeId=<%=Request["newsTypeId"] %>'>
                                <img src="../images/bt_edit.gif" alt="修改" title="修改" /></a> 
                            <a href="EditFirstNews.aspx?newsid=<%# Eval("id") %>"><img src="../images/bt_deal.gif" alt="设置头条" title="设置头条" /></a>
                                <a href='delete.aspx?id=<%# Eval("id") %>&page=<%=GetPage() %>'
                                    onclick="return confirm('确定删除？')">
                                    <img src="../images/bt_del.gif" alt="删除" />
                                </a>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
            <tr>
                <th colspan="9" class="pager">
                    <div class="pager">
                        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="15" UrlPaging="True"
                            OnPageChanged="AspNetPager1_PageChanged">
                        </webdiyer:AspNetPager>
                    </div>
                </th>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
